﻿using System.Collections.ObjectModel;
using System.Linq;

using OpenCvSharp;

using Xc.DataAccess.CodeReader.Properties;
using Xc.DataAccess.Core;

namespace Xc.DataAccess.CodeReader.Models.Filters
{
    /// <summary>
    /// 绘制匹配信息
    /// </summary>
    [Filter("绘制匹配信息", FilterType.Draw)]
    public class DrawMatches:FilterBase
    {
        /// <summary>
        /// 图1点信息
        /// </summary>
        [OutputParameter("图1点信息")]
        public ObservableCollection<CVKeyPoint> Point1 { get; set; } = new ObservableCollection<CVKeyPoint>();
        /// <summary>
        /// 图2
        /// </summary>
        [InputParameter("图2")]
        public Mat Image2 { get; set; }
        /// <summary>
        /// 图2点信息
        /// </summary>
        [OutputParameter("图2点信息")] 
        public ObservableCollection<CVKeyPoint> Point2 { get; set; } = new ObservableCollection<CVKeyPoint>();
        /// <summary>
        /// 匹配信息
        /// </summary>
        [OutputParameter("匹配信息")] 
        public ObservableCollection<DMatch> Matches { get; set; } = new ObservableCollection<DMatch>();
        /// <summary>
        /// 匹配颜色
        /// </summary>
        [InputParameter("匹配颜色")] 
        public Scalar MatchColor { get; set; }
        /// <summary>
        /// 单点颜色
        /// </summary>
        [InputParameter("单点颜色")] 
        public Scalar SinglePointColor { get; set; }
        /// <summary>
        /// 匹配点信息
        /// </summary>
        [InputParameter("遮盖信息")] 
        public ObservableCollection<byte> MatchMaskes { get; set; } = new ObservableCollection<byte>();
        /// <summary>
        /// 匹配标志
        /// </summary>
        [InputParameter("绘制模式")]
        public DrawMatchesFlags DrawMatchesFlags { get; set; }
        internal override ResultData<Mat> UseChannel(Mat mat, FilterBase[] filterInfos, FilterBase preFilterBase)
        {
            Mat result = new Mat();
            Cv2.DrawMatches(mat, Point1.Select(p => (KeyPoint)p).ToArray(), Image2, Point2.Select(p => (KeyPoint)p).ToArray(), Matches, result, MatchColor,SinglePointColor, MatchMaskes, DrawMatchesFlags);
            return ResultData<Mat>.Accept(TextResource.filter_action_complete, result);

        }
    }

}
